<%@ page import="instructor.sample.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%
	String today = null;
	Today t = new Today();
	today = t.getToday();
	request.setAttribute("picture", "MRDevice");
	request.setAttribute("title", "Customer Listing");
	request.setAttribute("header", "Welcome : Today is " + today);

	Customer c = new Customer();
	try {
		c.setCustomer(Integer.parseInt(request.getParameter("customerid").toString()));
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
<%@ include file="header.jsp"%>
<TD width="850" vAlign="top">

	<form name=form1 action=customerupdate.jsp method=post
		onSubmit="return validateForm()">
		<table width=100%>
			<tr>
				<td>
					<table>
						<tr>
							<td vAlign="Top" width="300"><p>Customer ID:</p></td>
							<td><input type="text" name="customerid" size="10"
								maxlength="9" readonly="readonly"
								value="<%=c.getCustomerid()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Customer Name:</p></td>
							<td vAlign="Top" width="150"><input type="text"
								name="customername" size="46" maxlength="45"
								value="<%=c.getCustomerName()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Customer Type:</p></td>
							<td vAlign="Top" width="150"><input type="text"
								name="customertype" size="31" maxlength="30" readonly="readonly"
								value="<%=c.getCustomerTypeDesc()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Billing Street:</p></td>
							<td vAlign="Top" width="150"><input type="text"
								name="billingstreet" size="31" maxlength="30"
								value="<%=c.getBillingstreet()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Billing City</td>
							<td vAlign="Top" width="300"><input type="text"
								name="billingcity" size="21" maxlength="20"
								value="<%=c.getBillingcity()%>" />* State<input type="text"
								name="billingstate" size="3" maxlength="2"
								value="<%=c.getBillingstate()%>" />* Zip<input type="text"
								name="billingzip" size="6" maxlength="5" value="<%=c.getBillingzip()%>" />*
								</p></td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Customer First Name</p></td>
							<td vAlign="Top" width="150"><input type="text"
								name="contactfirstname" size="21" maxlength="20"
								value="<%=c.getFirstname()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Customer Last Name</p></td>
							<td vAlign="Top" width="150"><input type="text"
								name="contactlastname" size="21" maxlength="20"
								value="<%=c.getLastname()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Phone Number</p></td>
							<td vAlign="Top" width="150"><input type="text"
								name="contactphone" size="16" maxlength="15"
								value="<%=c.getPhone()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Email</p></td>
							<td vAlign="Top" width="150"><input type="text"
								name="contactemail" size="51" maxlength="50"
								value="<%=c.getEmail()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><p>Position</p></td>
							<td vAlign="Top" width="150"><input type="text"
								name="contactposition" size="31" maxlength="30"
								value="<%=c.getPosition()%>" />*</td>
						</tr>
						<tr>
							<td vAlign="Top" width="300"><br>
								<p>
									<input type="submit" name="submit" value="Update" />
								</p></td>
							<td vAlign="Top" width="300"><br>
								<p>* The indicated fields are required</p></td>
						</tr>
					</table>
					<hr> <%
 	if (Integer.parseInt(request.getParameter("msgerror").toString()) == 1) {
 %> <i><p style="font-style: italic; color: red">Update
							Successful</p></i> <%
 	} else if (Integer.parseInt(request.getParameter("msgerror").toString()) == 0) {
 %> <i><p style="font-style: italic; color: red">
							Update <b>FAILED</b>
						</p></i> <%
 	}
 %>
				</td>
			</tr>
		</table>
		<!-- Insert more Form/Table tags here -->
</TD>
</TR>
</TABLE>

</BODY>

<script Language=JavaScript>
	function validateForm() {
		if (form1.customerid.value == "" && isNaN(form1.customerid.value)) {
			alert("Invalid customer id!");
			return false;
		}
		if (form1.customername.value == "") {
			alert("Invalid customer name!");
			return false;
		}
		if (form1.billingzip.value != "" && isNaN(form1.billingzip.value)) {
			alert("Invalid zipcode!");
			return false;
		}
	}
</script>
</html>